/*  * 
  *  @author pbalogh
  */
class Spring {

	private var _ideallength_y : Number;

	private var _ideallength_x : Number;

	private var _strength : Number;
	
	private var _sp:Terminus;  // "starting point" -- arbitrary -- could be either end, just pick one
	
	private var _ep:Terminus; // "end point" -- again, arbitrary -- the movie clip that isn't your starting point
	
	//each spring is attached to two terminii.
	//we designate one as the starting point and the other as the ending point
	//just to make life simple.

	
	public function Spring( sp: Terminus, ep : Terminus, strength : Number) 
	{
		_sp = sp;
		_ep = ep;
		trace("You made a spring");
		_ideallength_y = ep._y - sp._y;
		_ideallength_x = ep._x - sp._x;
		_strength = strength;
	}
	
	public function onEnterFrameHandler() :Void
	{
		//every good spring
		//will impart some force upon its two terminii.
		//thus affecting their velocities.
		//leaving it up to them to actually move.
		
		var top : Number = _sp._y;
		var bottom : Number = _ep._y;
	
		var springlength_y : Number = bottom - top;
		var springlength_x : Number = _ep._x - _sp._x;
		var stretch_y : Number = springlength_y - _ideallength_y;
		var stretch_x : Number = springlength_x - _ideallength_x;
		if (! _sp.locked) 
		{
	
			_sp.receiveForce( stretch_x * _strength, stretch_y * _strength );
			
		}
		
		if (! _ep.locked) 
		{
			
			_ep.receiveForce( -stretch_x * _strength, -stretch_y * _strength );
			
		}

//	drawLine(this.ep, this.sp);
};
	
}